package net.mysoft.budgetsoft.system.action;

import java.util.Set;

import net.mysoft.budgetsoft.system.domain.TMenu;
import net.mysoft.budgetsoft.system.service.MainService;
import net.mysoft.framework.base.BaseAction;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Results({
	@Result(name="index", location = "/platform/index.jsp"),
	@Result(name="north", location = "/platform/layout/north.jsp"),
	@Result(name="south", location = "/platform/layout/south.jsp"),
	@Result(name="center", location = "/platform/layout/center.jsp"),
	@Result(name="west", location = "/platform/layout/west.jsp"),
	@Result(name="east", location = "/platform/layout/east.jsp")}
)
@Namespace("/main")
@Scope("prototype")
@Controller
public class MainAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -226825754756847242L;
	
	@Autowired
	private MainService mainService;
	
	@Action("index")
	public String execute() throws Exception {
		return "index";
	}
	
	@Action("north")
	public String north() {
		return "north";
	}
	@Action("south")
	public String south() {
		return "south";
	}
	@Action("center")
	public String center() {
		return "center";
	}
	@Action("west")
	public String west() {
		Set<TMenu> menus = mainService.getUserRootMenus(super.getCurrentUser().getId());
		getRequest().setAttribute("roots", menus);
		return "west";
	}
	@Action("east")
	public String east() {
		return "east";
	}

}
